package com.arsn.myf.security.entity;

import com.arsn.myf.system.entity.User;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.Set;

/**
 * 用户信息,用于登录返回
 * @author arsn
 * @since 2022-06-06
 */
@Data
@Accessors(chain = true)
public class UserInfo implements UserDetails, Serializable {
    private Long id;

    private String username;

    private String password;

    private Set<? extends GrantedAuthority> authorities;

    /**
     * 用户唯一标识
     */
    private String token;

    /**
     * 登录时间
     */
    private Long loginTime;

    /**
     * 过期时间
     */
    private Long expireTime;

    /**
     * 环境
     */
    private String env;


    @Override
    public String getPassword() {
        return this.password;
    }

    /**
     * 用户信息
     */
    private User user;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
